package org.jsbd.boss.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.IChannelApkConfigDAO;
import org.jsbd.boss.dao.IDaylimitDAO;
import org.jsbd.boss.domian.DaylimitBean;
import org.jsbd.boss.domian.DaylimitBeanVO;
import org.jsbd.boss.domian.channel.ChannelApkConfig;
import org.jsbd.boss.service.IDaylimitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("daylimitService")
public class DaylimitServiceImpl implements IDaylimitService {
	
	@Autowired
	private IDaylimitDAO daylimitDAO;
	@Autowired
	private IChannelApkConfigDAO channelApkConfigDAO;
	
	/**
	 * 获取所有数据
	 */
	@Override
	public Map<String, Object> findDataWithPage(DataGridModel page, DaylimitBeanVO daylimitBeanVO) {
		return daylimitDAO.findDataWithPage(page, daylimitBeanVO);
	}

	/**
	 * 新增
	 */
	@Override
	public void save(DaylimitBean daylimitBean) {
		daylimitDAO.insert(daylimitBean);
	}

	/**
	 * 查询单个实例
	 */
	@Override
	public DaylimitBean findDaylimit(Integer id) {
		return daylimitDAO.selectOne(id);
	}

	/**
	 * 修改
	 */
	@Override
	public void modifyDaylimit(DaylimitBean daylimitBean) {
		daylimitDAO.updateDAO(daylimitBean);
	}

	/**
	 * 删除
	 */
	@Override
	public void delete(Integer id) {
		daylimitDAO.delete(id);
	}

	/**
	 * 获取增量数据
	 */
	@Override
	public List<DaylimitBean> findDeltaData(int offset) {
		return daylimitDAO.selectDeltaData(offset);
	}

	/**
	 * 更新daylimit
	 */
	@Override
	@Transactional("transactionManagerCrack")
	public void updateDaylimit(List<ChannelApkConfig> channelApkConfigs, List<DaylimitBean> daylimitBeans) {
		channelApkConfigDAO.updateDaylimit(channelApkConfigs);
		daylimitDAO.updateIsExecute(daylimitBeans);
	}

	/**
	 * 验证是否存在mark
	 */
	@Override
	public boolean hasMark(String mark) {
		ChannelApkConfig channelApkConfig = channelApkConfigDAO.getByMark(mark);
		if (null == channelApkConfig) {
			return false;
		}
		return true;
	}

	@Override
	public boolean isRepeat(String mark) {
		DaylimitBean daylimitBean = daylimitDAO.getByMark(mark);
		if (null == daylimitBean) {
			return false;
		}
		return true;
	}

}
